package com.lsy.on_line.zaixian.Exception;

import com.lsy.on_line.zaixian.utils.JsonData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 异常处理类
 */
@ControllerAdvice
public class CustomExceptionHandler {

    private final static Logger logger = LoggerFactory.getLogger(CustomExceptionHandler.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public JsonData handler(Exception e){

        logger.error("【系统异常】"+"{"+ e +"}");
        if (e instanceof ZXException){
            ZXException zxException = (ZXException) e;
            return JsonData.buildError(zxException.getCode(),zxException.getMsg());
        }else {

        }
        return JsonData.buildError("全局异常,未知的错误");
    }

}
